package com.tang.fitten_cod;

import java.util.concurrent.CompletableFuture;

public class AsyncExample {
    public static void main(String[] args) {
        CompletableFuture<Void> futureC = CompletableFuture.runAsync(() -> {
            // 执行C单元的任务
            System.out.println("C单元执行完毕");
        });

        CompletableFuture<Void> futureB = CompletableFuture.runAsync(() -> {
            // 执行B单元的任务
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("B单元执行完毕");
        });

        CompletableFuture<Void> futureA = CompletableFuture.anyOf(futureC, futureB).thenRun(() -> {
            // 执行A单元的任务
            System.out.println("A单元执行完毕");
        });

        futureA.join(); // 等待A单元执行完毕
    }
}
